package com.momoauth.api_client.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.momoauth.api_client.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    /**
     * 查询角色列表
     * @return
     */
    @Select("SELECT role.roleId,role.roleName,role.status,role.createTime," +
            "(SELECT COUNT(1) FROM user_role WHERE role_id = roleId) AS roleUseNum " +
            "FROM `role` WHERE isDelete = 0 ORDER BY roleId DESC LIMIT 10")
    List<Role> getRoleList();

    /**
     * 删除角色
     * @param role
     * @return
     */
    @Update("UPDATE role SET isDelete = 1 WHERE roleId = #{roleId}")
    Integer deleteRoleById(Role role);
}
